

let Constant = require('./constant')

class baseModel {
    constructor(data, message) {
        if (typeof data === 'string') {
            this.message = data;
            data = null;
            message = null;
        }
        if (data) {
            this.data = data;
        }
        if (message) {
            this.message = message;
        }
    }
}

// 成功返回
class Success extends baseModel {
    constructor(data, message) {
        if (!message) {
            message = Constant.returnData.success.msg;
        }
        super(data, message);
        this.code = Constant.returnData.success.code;
    }
}

//入参错误
class Error extends baseModel {
    constructor(data, message) {
        if (!message) {
            message = Constant.returnData.error.msg;
        }
        super(data, message);
        this.code = Constant.returnData.error.code;
    }
}

//该数据不存在
class Def extends baseModel {
    constructor(data, message) {
        if (!message) {
            message = Constant.returnData.def.msg;
        }
        super(data, message);
        this.code = Constant.returnData.def.code;
    }
}

//该数据已存在
class Exist extends baseModel {
    constructor(data, message) {
        if (!message) {
            message = Constant.returnData.exist.msg;
        }
        super(data, message);
        this.code = Constant.returnData.exist.code;
    }
}

//服务器发生异常
class Server extends baseModel {
    constructor(data, message) {
        if (!message) {
            message = Constant.returnData.server.msg;
        }
        super(data, message);
        this.code = Constant.returnData.server.code;
    }
}

//token过期
class Due extends baseModel {
    constructor(data, message) {
        if (!message) {
            message = Constant.returnData.due.msg;
        }
        super(data, message);
        this.code = Constant.returnData.due.code;
    }
}

//该数据已删除
class Delete extends baseModel {
    constructor(data, message) {
        if (!message) {
            message = Constant.returnData.delete.msg;
        }
        super(data, message);
        this.code = Constant.returnData.delete.code;
    }
}

exports.Success = Success; // 成功
exports.Error = Error; // 入参错误
exports.Def = Def; // 该数据不存在
exports.Exist = Exist; // 该数据已存在
exports.Server = Server; // 服务器发生异常
exports.Due = Due; // token过去
exports.Delete = Delete; // 该数据已删除